<!DOCTYPE html>
<html>
<head>
	<title>js_cookie</title>
</head>
<body>
	<script type="text/javascript">
		//js对cookie的操作

		//设置cookie
		function setCookie(c_name, c_value, c_expiredays) {
			var expires = "";
			if(c_expiredays!=null){
				var sysDate = new Date();
				//alert(sysDate.toUTCString());
				sysDate.setDate(sysDate.getDate()+c_expiredays)
				//alert(sysDate.toUTCString());
				expires = ";expires=" + sysDate.toUTCString();
			}
			document.cookie = c_name+"="+escape(c_value)+expires;
		}

		setCookie("ssid", "abc", 1);
		setCookie("vvid", "123", 1);
		setCookie("ccid", "sjkc", 1);

		alert(document.cookie);


		//获取cookie
		function getCookie(c_name){
			if(document.cookie.length>0){
				//通过字符串的截取
				var start = document.cookie.indexOf(c_name+"=");
				start = start + c_name.length + 1;
				var end = document.cookie.indexOf(";",start);
				if(end==-1) end = document.cookie.length;
				var val = document.cookie.substring(start,end);
				return unescape(val);
			}
		}

		alert(getCookie("vvid"));
		alert(getCookie("ccid"));

		function deleteCookie(c_name){
			var sysDate = new Date();
			sysDate.setDate(sysDate.getDate()-1);
			var time = ";expires=" + sysDate.toUTCString();
			var val = getCookie(c_name);
			document.cookie = c_name+"="+escape(val)+time;
		}

		deleteCookie("ccid");

		alert(document.cookie);

	</script>
</body>
</html>